package com.java83.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java83.entity.RbacPerm;
import com.java83.service.RbacManagerPermService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (RbacPerm)表控制层
 *
 * @author makejava
 * @since 2021-11-26 13:02:35
 */
@RestController
@RequestMapping("rbacManagerPerm")
public class RbacManagerPermController {
    /**
     * 服务对象
     */
    @Resource
    private RbacManagerPermService rbacManagerPermService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<RbacPerm> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.rbacManagerPermService.queryById(id));
    }

    /**
     * 通过页数查询数据
     *
     * @param startPage 页码号
     * @param pageSize 页码所需对象个数
     * @return 单条数据
     */
    @GetMapping("{startPage}/{pageSize}")
    public PageInfo<RbacPerm> queryAll(@PathVariable("startPage") int startPage, @PathVariable("pageSize") int pageSize) {
        PageHelper.startPage(startPage,pageSize);
        List<RbacPerm> list =  rbacManagerPermService.queryAll();
        PageInfo<RbacPerm> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 新增数据
     *
     * @param rbacManagerPerm 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<RbacPerm> add(RbacPerm rbacManagerPerm) {
        return ResponseEntity.ok(this.rbacManagerPermService.insert(rbacManagerPerm));
    }

    /**
     * 编辑数据
     *
     * @param rbacManagerPerm 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<RbacPerm> edit(RbacPerm rbacManagerPerm) {
        return ResponseEntity.ok(this.rbacManagerPermService.update(rbacManagerPerm));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.rbacManagerPermService.deleteById(id));
    }

}

